﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace xiaolanshu
{
    public partial class 护肤评价1 : Form
    {
        public SqlConnection conn;
        public 护肤评价1()
        {
            InitializeComponent();
            conn = SQLTools.conn;
        }

        private void 护肤评价1_Load(object sender, EventArgs e)
        {
            string sql = "select 商品名称 from 护肤";
            SqlCommand cmd = new SqlCommand(sql, conn);
            if (cmd.Connection.State == ConnectionState.Open)
            {
                cmd.Connection.Close();
            }
            conn.Open();
            SqlDataReader rd = cmd.ExecuteReader();
            while (rd.Read())
            {
                comboBox1.Items.Add(rd[0]);
            }
            rd.Close();
            conn.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //string sql = @"select AVG(整体评价)as pj,AVG(美白效果) as mb,AVG(保湿控油效果) as bs,AVG(吸收效果) as xs from 护肤反馈 where 商品名称=@商品名称 ";
            //SqlCommand cmd = new SqlCommand(sql, conn);
            //cmd.Parameters.Add("@商品名称", SqlDbType.VarChar, 50);
            //cmd.Parameters["@商品名称"].Value = comboBox1.Text;
            SqlCommand cmd = new SqlCommand("skincare", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@name", SqlDbType.VarChar, 50);
            cmd.Parameters["@name"].Value = comboBox1.Text;
            cmd.Parameters.Add("@pj", SqlDbType.Int);
            cmd.Parameters.Add("@mb", SqlDbType.Int);
            cmd.Parameters.Add("@bs", SqlDbType.Int);
            cmd.Parameters.Add("@xs", SqlDbType.Int);
            cmd.Parameters["@pj"].Direction = ParameterDirection.Output;
            cmd.Parameters["@mb"].Direction = ParameterDirection.Output;
            cmd.Parameters["@bs"].Direction = ParameterDirection.Output;
            cmd.Parameters["@xs"].Direction = ParameterDirection.Output;
            SqlDataAdapter da=new SqlDataAdapter(cmd);
            da.SelectCommand = cmd;
            DataSet ds = new DataSet();
            da.Fill(ds, "pingjia");
            textBox1.Text = cmd.Parameters["@pj"].Value.ToString();
            textBox2.Text = cmd.Parameters["@mb"].Value.ToString();
            textBox3.Text = cmd.Parameters["@bs"].Value.ToString();
            textBox4.Text = cmd.Parameters["@xs"].Value.ToString();



            //conn.Open();
            //SqlDataReader rd = cmd.ExecuteReader();
            //if (rd.Read())
            //{
            //    textBox1.Text = rd["@pj"].ToString();
            //    textBox2.Text = rd["@mb"].ToString();
            //    textBox3.Text = rd["@bs"].ToString();
            //    textBox4.Text = rd["@xs"].ToString();
            //}
            //rd.Close();
            //conn.Close();
            string sql1 = @"select 肤质,整体评价,美白效果,保湿控油效果,吸收效果 from 护肤反馈 where 商品名称='"+ comboBox1.Text+"'";
            SqlDataAdapter ad = new SqlDataAdapter(sql1, conn);
            DataSet ds1 = new DataSet();
            ad.Fill(ds1, "t");
            dataGridView1.DataSource = ds1.Tables["t"];
        }
    }
}
